package com.mas.framework.jackson.core.databind;

import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author godyao
 * @description 将 yyyy-MM-dd HH:mm:ss 转化为LocalDateTime
 * @date 2023年01月21日13:36
 */
public class LocalDateTimeDeSerializer extends JsonDeserializer<LocalDateTime> {
    public static final LocalDateTimeDeSerializer INSTANCE = new LocalDateTimeDeSerializer();

    @Override
    public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        return LocalDateTime.parse(p.getText(), DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));

        //return LocalDateTime.ofInstant(Instant.ofEpochSecond(p.getValueAsLong()), ZoneId.systemDefault());
    }
}
